// component/singleSelectPop/singleSelectPop.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    popType: {
      type: String,
      value: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    customArr: {
      type: Array,
      value: []
    },
    popTitle: {
      type: String,
      value: ""
    }
  },


  /**
   * 组件的初始数据
   */
  data: {
    result: null,
    //选择数据源
    dataArr: [],
    cArr: [],
    type: "",//单选类型
    title: "",//标题
    //佣金设置类型
    commissionSettingArr: [
      {
        value: 1,
        label: "副盘",
      },
      {
        value: 2,
        label: "主佣金"
      },
      {
        value: 3,
        label: "其它"
      },
    ],
    buyHouseCategorys: [
      {
        value: "住宅",
        label: "住宅",
      },
      {
        value: "公寓",
        label: "公寓"
      },
      {
        value: "商铺",
        label: "商铺"
      },
      {
        value: "写字楼",
        label: "写字楼"
      },
      {
        value: "租赁",
        label: "租赁"
      }

    ],
    devCompanyArr: [
      {
        value: "shunfeng",
        label: "顺丰"
      },
      {
        value: "yuantong",
        label: "圆通"
      },
      {
        value: "zhongtong",
        label: "中通"
      },
      {
        value: "shentong",
        label: "申通"
      },
      {
        value: "yunda",
        label: "韵达"
      },
      {
        value: "jd",
        label: "京东"
      },
      {
        value: "youzhengguonei",
        label: "邮政快递包裹"
      },
      {
        value: "huitongkuaidi",
        label: "百世快递"
      },
      {
        value: "jtexpress",
        label: "极兔快递"
      },
      {
        value: "tiantian",
        label: "天天快递"
      },
      {
        value: "debangwuliu",
        label: "德邦"
      },
      {
        value: "debangkuaidi",
        label: "德邦快递"
      },
      {
        value: "zhaijisong",
        label: "宅急送"
      },
      {
        value: "lianbangkuaidi",
        label: "联邦快递"
      },
      {
        value: "danniao",
        label: "丹鸟"
      },

    ],
    //行政区域:
    adAreaArr: [
      {
        value: "",
        label: "不限",
      },
      {
        value: "金牛区",
        label: "金牛区"
      },
      {
        value: "锦江区",
        label: "锦江区"
      },
      {
        value: "青羊区",
        label: "青羊区"
      },
      {
        value: "武侯区",
        label: "武侯区"
      },
      {
        value: "成华区",
        label: "成华区"
      },
      {
        value: "双流区",
        label: "双流区"
      },
      {
        value: "龙泉驿区",
        label: "龙泉驿区"
      },
      {
        value: "新都区",
        label: "新都区"
      },
      {
        value: "温江区",
        label: "温江区"
      },
      {
        value: "青白江区",
        label: "青白江区"
      },
      {
        value: "新津区",
        label: "新津区"
      },
      {
        value: "郫都区",
        label: "郫都区"
      },
      {
        value: "都江堰市",
        label: "都江堰市"
      },
      {
        value: "崇州市",
        label: "崇州市"
      },
      {
        value: "大邑县",
        label: "大邑县"
      },
      {
        value: "彭州市",
        label: "彭州市"
      },
      {
        value: "邛崃市",
        label: "邛崃市"
      },
      {
        value: "金堂县",
        label: "金堂县"
      },
      {
        value: "蒲江县",
        label: "蒲江县"
      },
      {
        value: "简阳市",
        label: "简阳市"
      },
      {
        value: "眉山市",
        label: "眉山市"
      },


    ],
    yxArr: [
      {
        value: "高",
        label: "高",
      },
      {
        value: "中",
        label: "中",
      },
      {
        value: "低",
        label: "低",
      },
    ],
    adPriceArr: [
      {
        value: "",
        label: "不限",
      },
      {
        value: "1-10000",
        label: "10000元/㎡以下"
      },
      {
        value: "10000-15000",
        label: "10000-15000元/㎡"
      },
      {
        value: "15000-20000",
        label: "15000-20000元/㎡"
      },
      {
        value: "20000-30000",
        label: "20000-30000元/㎡"
      },
      {
        value: "30000-90000",
        label: "30000元/㎡以上"
      },

    ],
    //总价:
    totalPriceArr: [
      {
        value: "",
        label: "不限",
      },
      {
        value: "50",
        label: "50万",
      },
      {
        value: "80",
        label: "80万",
      },
      {
        value: "100",
        label: "100万",
      },
      {
        value: "120",
        label: "120万",
      },
      {
        value: "150",
        label: "150万",
      },
      {
        value: "200",
        label: "200万",
      },
      {
        value: "250",
        label: "250万",
      },
      {
        value: "300",
        label: "300万",
      },
      {
        value: "400",
        label: "400万",
      },
      {
        value: "500",
        label: "500万",
      },
      {
        value: "600",
        label: "500万+",
      },
    ],
    yearArr: [
      {
        value: "2021-01-01",
        label: "2021年"
      },
      {
        value: "2022-01-01",
        label: "2022年"
      },
      {
        value: "2023-01-01",
        label: "2023年"
      },
      {
        value: "2024-01-01",
        label: "2024年"
      },
      {
        value: "2025-01-01",
        label: "2025年"
      },
      {
        value: "2026-01-01",
        label: "2026年"
      },
      {
        value: "2027-01-01",
        label: "2027年"
      }
    ],
    roleNames: [
      // {
      //   label: "普通用户",
      //   value: "1",
      // },
      {
        label: "全民分销",
        value: "3",
      },
      {
        label: "置业顾问",
        value: "5",
      },
      {
        label: "经纪人",
        value: "7",
      },
      {
        label: "公司",
        value: "9",
      }
    ],
    //区域
    areaArr: [
      {
        value: "",
        label: "不限",
      },
      {
        value: "金牛区",
        label: "金牛区",
      },
      {
        value: "武侯区",
        label: "武侯区",
      },
      {
        value: "青羊区",
        label: "青羊区",
      },
      {
        value: "锦江区",
        label: "锦江区",
      },
      {
        value: "新都区",
        label: "新都区",
      },
      {
        value: "郫都区",
        label: "郫都区",
      },
      {
        value: "高新区",
        label: "高新区",
      }, {
        value: "成华区",
        label: "成华区",
      }, {
        value: "双流区",
        label: "双流区",
      },
      {
        value: "龙泉驿区",
        label: "龙泉驿区",
      },
      {
        value: "温江区",
        label: "温江区",
      },
      {
        value: "青白江区",
        label: "青白江区",
      },
      {
        value: "简阳市",
        label: "简阳市",
      },
      {
        value: "新津区",
        label: "新津区",
      },
      {
        value: "金堂县",
        label: "金堂县",
      },
      {
        value: "大邑县",
        label: "大邑县",
      },
      {
        value: "都江堰市",
        label: "都江堰市",
      },
      {
        value: "彭州市",
        label: "彭州市",
      },
      {
        value: "邛崃市",
        label: "邛崃市",
      },
      {
        value: "崇州市",
        label: "崇州市",
      },
      {
        value: "眉山市",
        label: "眉山市",
      },




    ],
    //首付:
    firstPayArr: [
      {
        value: "",
        label: "不限",
      },
      {
        value: "30",
        label: "30万",
      },
      {
        value: "40",
        label: "40万",
      },
      {
        value: "50",
        label: "50万",
      },
      {
        value: "60",
        label: "60万",
      },
      {
        value: "70",
        label: "70万",
      },
      {
        value: "80",
        label: "80万",
      },
      {
        value: "100",
        label: "100万",
      },
      {
        value: "120",
        label: "120万",
      },
      {
        value: "150",
        label: "150万",
      },
      {
        value: "200",
        label: "200万",
      },
      {
        value: "250",
        label: "200万+",
      },
    ],
    //房屋装修arr:
    houseDecorations: [
      {
        value: "毛坯",
        label: "毛坯",
      },
      {
        value: "简装",
        label: "简装",
      },
      {
        value: "精装",
        label: "精装",
      },
      {
        value: "豪装",
        label: "豪装",
      }
    ],
    //商业贷-房贷利率
    rateValues: [
      {
        value: "0.0465",
        label: "利率4.65%（LPR+0基点）"
      },
      {
        value: "0.0538",
        label: "利率5.38%（LPR+73基点）"
      },
      {
        value: "0.05437",
        label: "利率5.437%（LPR+78.7基点）"
      },
      {
        value: "0.0544",
        label: "利率5.44%（LPR+79基点）"
      },
      {
        value: "0.05485",
        label: "利率5.485%（LPR+83.5基点）"
      },
      {
        value: "0.0553",
        label: "利率5.53%（LPR+88基点）"
      },
      {
        value: "0.05535",
        label: "利率5.535%（LPR+88.5基点）"
      },
      {
        value: "0.0578",
        label: "利率5.78%（LPR+113基点）"
      },
      {
        value: "custom",
        label: "自定义利率"
      },
    ],
    // 利率方式选择
    rateTypes: [
      {
        value: "LPR",
        label: "使用最新LPR"
      },
      {
        value: "old",
        label: "使用旧版利率"
      }
    ],
    //年限选择:
    years: [
      {
        value: 3,
        label: "3年"
      },
      {
        value: 5,
        label: "5年"
      },
      {
        value: 10,
        label: "10年"
      },
      {
        value: 15,
        label: "15年"
      },
      {
        value: 20,
        label: "20年"
      },
      {
        value: 25,
        label: "25年"
      },
      {
        value: 30,
        label: "30年"
      }
    ],
    //公积金利率
    fundRates: [
      {
        value: 0.0325,
        label: "3.25% （最新基准利率1倍）"
      },
      {
        value: 0.0358,
        label: "3.58% （最新基准利率1.1倍）"
      },
      {
        value: 0.039,
        label: "3.9% （最新基准利率1.2倍）"
      },
      {
        value: 0.0423,
        label: "4.23% （最新基准利率1.3倍）"
      }
    ],
    //旧版利率:
    oldRateValues: [
      {
        value: 0.0392,
        label: "3.92% （基准利率8折）"
      },
      {
        value: 0.04165,
        label: "4.165% （基准利率8.5折）"
      },
      {
        value: 0.0441,
        label: "4.41% （基准利率9折）"
      },
      {
        value: 0.04655,
        label: "4.655% （基准利率9.5折）"
      },
      {
        value: 0.049,
        label: "基准利率4.9%"
      },
      {
        value: 0.05145,
        label: "5.145% （基准利率上浮5%）"
      },
      {
        value: 0.0539,
        label: "5.39% （基准利率上浮10%）"
      },
      {
        value: 0.05635,
        label: "5.635% （基准利率上浮15%）"
      },
      {
        value: 0.0588,
        label: "5.88% （基准利率上浮20%）"
      },
      {
        value: 0.06125,
        label: "6.125% （基准利率上浮25%）"
      },
      {
        value: 0.0637,
        label: "6.37% （基准利率上浮30%）"
      },
      {
        value: "custom",
        label: "自定义利率"
      }

    ],
    sexArr: [
      {
        value: 1,
        label: "男"
      },
      {
        value: 2,
        label: "女"
      },
    ],
    //首付比例
    payRatios: [
      {
        value: 0.1,
        label: "10%"
      },
      {
        value: 0.2,
        label: "20%"
      },
      {
        value: 0.3,
        label: "30%"
      },
      {
        value: 0.4,
        label: "40%"
      },
      {
        value: 0.5,
        label: "50%"
      },
      {
        value: 0.6,
        label: "60%"
      },
      {
        value: 0.7,
        label: "70%"
      },
      {
        value: 0.8,
        label: "80%"
      },
      {
        value: 0.9,
        label: "90%"
      },
    ],
    //上午，下午数组
    morningArr: [
      {
        label: "上午",
        value: "上午"
      },
      {
        label: "下午",
        value: "下午"
      }
    ],
    afternoonArr: [
      {
        label: "下午",
        value: "下午"
      }
    ],
    experienceArr: [
      {
        label: "不限",
        value: "不限",
      },
      {
        label: "1年",
        value: "1年",
      },
      {
        label: "2年",
        value: "2年",
      },
      {
        label: "3年",
        value: "3年",
      },
      {
        label: "4年",
        value: "4年",
      },
      {
        label: "5年",
        value: "5年",
      },
      {
        label: "5年以上",
        value: "5年以上",
      },

    ],
    educationArr: [
      {
        label: "专科",
        value: "专科",
      },
      {
        label: "大专",
        value: "大专",
      },
      {
        label: "本科",
        value: "本科",
      },
      {
        label: "硕士",
        value: "硕士",
      },
      {
        label: "博士",
        value: "博士",
      },
    ],
    salaryArr: [
      {
        label: "2-5K",
        value: "2-5K",
      },
      {
        label: "5-8k",
        value: "5-8k",
      },
      {
        label: "8-12k",
        value: "8-12k",
      },
      {
        label: "12-15K",
        value: "12-15K",
      },
      {
        label: "15-20k",
        value: "15-20k",
      },
      {
        label: "20k以上",
        value: "20k以上",
      },
      {
        label: "面议",
        value: "面议",
      },
    ],
    isScroll: false,





  },
  observers: {
    'popType': function (newValue) {
      this.setData({
        type: newValue
      })
      this.dataConfig();
    },
    'popTitle': function (newValue) {
      this.setData({
        title: newValue
      })
    },
    'customArr': function (newValue) {
      // console.log("监听到改变了吗=====:" + JSON.stringify(newValue));
      this.setData({
        cArr: newValue,
        dataArr: newValue,
        result: newValue[0]
      })
      // this.setData({
      //   dataArr: this.data.cArr
      // })
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.setData({
        type: this.properties.popType
      })
      if (this.properties.customArr.length > 0) {
        this.setData({
          dataArr: this.properties.customArr,
          // result: this.properties.customArr[0]
        })
      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dataConfig() {
      //取配置数组
      console.log("JJLog:来没有啊=====:" + this.data.type);
      switch (this.data.type) {
        case "decoration":
          this.setData({
            dataArr: this.data.houseDecorations
          })
          break;
        case "rateValue":
          this.setData({
            dataArr: this.data.rateValues
          })
          break;
        case "oldRate":
          this.setData({
            dataArr: this.data.oldRateValues
          })
          break;
        case "rateType":
          this.setData({
            dataArr: this.data.rateTypes
          })
          break;
        case "year":
          this.setData({
            dataArr: this.data.yearArr
          })
          break;
        case "roleName":
          this.setData({
            dataArr: this.data.roleNames
          })
          break;
        case "fundYear":
        case "businessYear":
          this.setData({
            dataArr: this.data.years
          })
          break;
        case "fundRate":
          this.setData({
            dataArr: this.data.fundRates
          })
          break;
        case "commissionSetting":
          this.setData({
            dataArr: this.data.commissionSettingArr
          })
          break;
        case "payRatio":
          this.setData({
            dataArr: this.data.payRatios
          })
          break;
        case "lx":
          this.setData({
            dataArr: this.data.buyHouseCategorys
          })
          break;
        case "morning":
          this.setData({
            dataArr: this.data.morningArr
          })
          break;
        case "expressName":
          this.setData({
            dataArr: this.data.devCompanyArr
          })
          break;
        case "yx":
          this.setData({
            dataArr: this.data.yxArr
          })
          break;
        case "afternoon":
          this.setData({
            dataArr: this.data.afternoonArr
          })
          break;
        case "sex":
          this.setData({
            dataArr: this.data.sexArr
          })
          break;
        case "experience":
          this.setData({
            dataArr: this.data.experienceArr
          })
          break;
        case "education":
          this.setData({
            dataArr: this.data.educationArr
          })
          break;
        case "salary":
          this.setData({
            dataArr: this.data.salaryArr
          })
          break;
        case "firstPay":
          this.setData({
            dataArr: this.data.firstPayArr
          })
          break;
        case "totalPrice":
          this.setData({
            dataArr: this.data.totalPriceArr
          })
          break;
        case "areaName":
          this.setData({
            dataArr: this.data.areaArr
          })
          break;
        case "adArea":
          this.setData({
            dataArr: this.data.adAreaArr
          })
          break;
        case "adPrice":
          this.setData({
            dataArr: this.data.adPriceArr
          })
          break;
        case "custom":
          console.log("JJLog:" + JSON.stringify(this.data.cArr));
          this.setData({
            dataArr: this.data.cArr
          })
          break;

        default:
          this.setData({
            dataArr: this.properties.customArr
          })
          break;

      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    clickCenterPopupOverlay() {
      this.triggerEvent('popHide', { show: false });
    },
    //关闭弹窗
    popupCancel() {
      this.triggerEvent('popHide', { show: false });
    },
    //确认选择:
    popupTrue() {
      // this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      if (!this.data.isScroll) {
        this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      }
    },
    //最后的value:
    bindChange(e) {
      console.log("JJLog:新组建选中时:" + JSON.stringify(e));
      let index = e.detail.value[0];
      let value = this.data.dataArr[index];
      console.log("JJLog:选择到的值是:" + JSON.stringify(value));
      this.setData({
        result: value
      })
    },
    bindStartAction() {
      this.setData({
        isScroll: true
      })
    },
    bindEndAction() {
      this.setData({
        isScroll: false
      })
    },
  }
})
